package bancosys.tec.rtm.impl.diagnostician;

import java.math.BigDecimal;

import jmine.tec.utils.math.MathUtils;
import bancosys.tec.rtm.diagnostician.DiagnosisBean;

/**
 * Diagnostician que mede a performance da CPU
 * 
 * @author takeshi
 */
public class CPUUseDiagnostician extends AbstractPerformanceDiagnostician {

    private static final int ITERATIONS_WARMUP = 10;

    private static final int NUM_ITERATIONS = 400;

    private static final int SOME_NUMBER = 42;

    /**
     * {@inheritDoc}
     */
    public String getName() {
        return "CPUUseDiagnostician";
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected void warmupStep() throws Exception {
        MathUtils.nthRoot(BigDecimal.valueOf(1), 1, ITERATIONS_WARMUP);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected void performOperation(DiagnosisBean bean) throws Exception {
        BigDecimal result = MathUtils.nthRoot(BigDecimal.valueOf(SOME_NUMBER), SOME_NUMBER, NUM_ITERATIONS);
        bean.addDescription("Calculated result of 42 ^ (1/42) " + result);
        bean.addDescription("expected value around 1.093072058");
    }

}
